import * as React from 'react'
import './index.scss'
import * as ReactDOM from 'react-dom'
let timer = null
class Toast{
    static info(msg, timeout) {
      msg = msg ||"info"
      timeout = timeout || 2000
        init()
        setTime(timeout)
        ReactDOM.render(
            <span>{msg}</span>, document.getElementById('dark-toast'));
    }
}

function init () {
    clearTimeout(timer)
    let dark_toast = document.getElementById('dark-toast')
    if (dark_toast) {
        dark_toast.style.display = "block"
    } else {
        let div = document.createElement("div")
        div.setAttribute("id", "dark-toast")
        document.body.appendChild(div);
    }
}
function setTime (timeout) {
    timer = setTimeout (() => {
        let dark_toast = document.getElementById('dark-toast')
        if (dark_toast) {
            dark_toast.style.display = "none"
        }
    }, timeout)
}
export default Toast